<template>
	<view>
		<image class="pagebg" :src="apifun.serveimg+'selectenterprisebg.png'" mode=""></image>
		<view class="back" :style="{'height':statusheadheight+'px'}">
			<view class="backicon">
				<uv-icon name="arrow-left" size="22" color="#03253D"></uv-icon>
			</view>
		</view>
		<view class="seletitle">
			<image :src="apifun.serveimg+'selectctentertitle.png'" mode="heightFix"></image>
		</view>
		<view class="enterprise">
			<view class="enterpriseeach marginAuto" @click="acpriseid = item.id" v-for="(item,index) in datas" :key="index">
				<view class="enterpriseac mainBg" v-if="acpriseid == item.id">
					<uv-icon name="checkbox-mark" color="#ffffff" size="18"></uv-icon>
				</view>
				<view class="enterprisetitle flex">
					<view class="enterprisetitlen marginAuto flex">
						<view class="enterprisetitlent ellipsis01" >{{ item.company_name }}</view>
						<view class="enterprisetitlela" v-if="item.company_type.includes('1')">工业</view>
						<view class="enterprisetitlela" v-if="item.company_type.includes('2')">农业</view>
					</view>
				</view>
			</view>
		</view>
		<view class="marginAuto" style="width:600rpx;margin-top:100rpx;">
			<uv-button text="确定" @click="enter()" :customStyle="{
				'background':'#2340FF',
				'color':'#fff',
				'font-size':'30rpx',
				'width':'600rpx',
				'height':'100rpx',
				'border-radius':'20rpx'
			}"></uv-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusheadheight:uni.getStorageSync('ClientRectTop')+uni.getStorageSync('ClientRectHeight'),
				apifun:this.apifun,
				datas:[],
				acpriseid:''
			};
		},
		onLoad() {
			this.initData()
		},
		methods: {
			initData(){
				this.apifun.unirequest('/common/user/getUserCompanyList','post',{},(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.datas = datas;
						this.acpriseid = datas[0].id;
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			enter(){
				this.apifun.unirequest('/common/user/setLoginCompany','post',{company_id:this.acpriseid},(res)=>{
					if(res.code === 200){
						let datas = res.data;
						uni.reLaunch({
							url:'/pages/user/home'
						})
					}else{
						this.apifun.toast(res.msg)
					}
				})
			}
		},
	};
</script>

<style scoped lang="scss">
	page{
		padding-bottom: 100rpx;
	}
	.pagebg{
		position: fixed;
		top: 0;
		left: 0;
		z-index: 0;
		width: 100%;
		height: 100%;
	}
	.back{
		position:sticky;
		top: 0;
		z-index: 10;
		.backicon{
			position: absolute;
			bottom: 0;
			left: 24rpx;
		}
	}
	.seletitle{
		position: relative;
		z-index: 10;
		left: 24rpx;
		margin-top: 100rpx;
		image{
			height: 60rpx;
		}
	}
	.enterprise{
		margin-top: 100rpx;
		.enterpriseeach{
			position: relative;
			width: 690rpx;
			height: 160rpx;
			background-color: #fff;
			border-radius: 10rpx;
			margin-top:60rpx;
			.enterpriseac{
				position: absolute;
				right: 0;
				top: 0;
				padding: 0 10rpx;
				height: 40rpx;
				border-top-right-radius: 10rpx;
				border-bottom-left-radius:10rpx;
			}
			.enterprisetitle{
				line-height: 160rpx;
				.enterprisetitlen{
					.enterprisetitlent{
						width:100%;
					}
					.enterprisetitlela{
						width:100rpx;
						height: 46rpx;
						line-height: 46rpx;
						border-radius: 10rpx;
						color:#2340FF;
						font-size: 24rpx;
						text-align: center;
						border: 1px solid #2340FF;
						background-color: #EFF1FF;
						margin-top: 55rpx;
						margin-left: 10rpx;
					}
				}
			}
		}
	}
</style>